package cn.ante.ymcc.tokeninterceptor;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
/**
* @Description: 将当前请求头中的token带给feigin的请求头
* @Author: Nai
* @Version: 1.0
* @Date:  2022/8/27 23:43
*/
@Component
public class TokenForwordFeignInterceptor implements RequestInterceptor {
    // 获取到的token  从请求头中拿出来
    private static final String AUTHORIZATION_HEADER = "Authorization";

    @Override
    public void apply(RequestTemplate requestTemplate) {
        // 得到请求对象
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
       //  请求对象的请求中拿到头部请求里存入的token值
        String token = requestAttributes.getRequest().getHeader(AUTHORIZATION_HEADER);
        // 将token放在feign的请求头中
    }
}
